package com.demo.design.behavioral.strategy;

import com.demo.design.behavioral.strategy.impl.BinarySearchSort;
import com.demo.design.behavioral.strategy.impl.BubbleSort;

import java.util.HashMap;
import java.util.Map;

public class SortStrategy {

    private static Map<String, RootStrategy> ORDER_STRATEGY_MAP = new HashMap<>();

    static {
        ORDER_STRATEGY_MAP.put("bubble", new BubbleSort());
        ORDER_STRATEGY_MAP.put("binary", new BinarySearchSort());
    }

    public void setStrategy(RootStrategy rootStrategy, String name) {
        ORDER_STRATEGY_MAP.put(name, rootStrategy);
    }

    public RootStrategy getStrategy(String name) {
        RootStrategy rootStrategy = ORDER_STRATEGY_MAP.get(name);
        if (rootStrategy == null) {
            System.err.println("错误或者不存在的排序策略");
        }
        return rootStrategy;
    }
}
